/**
 *
 */
package hb.software.service.student.impl;

import hb.software.service.student.StudentManager;
import hb.software.student.dao.StudentDao;
import hb.software.student.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import edu.zut.hb.software.base.service.impl.GenericStudentManagerImpl;

import java.util.List;

/**
 * @author Mie
 *
 */
public class StudentManagerImpl extends GenericStudentManagerImpl<Student, Long> implements StudentManager {

	StudentDao studentDao;
	@Override
	public List<Student> findByName(String name) {
		// 创建查询条件数据对象
		Student queryObject = new Student();
		queryObject.setName(name);
		ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
				.withMatcher("name", GenericPropertyMatchers.startsWith()) // 姓名采用“开始匹配”的方式查询
				.withIgnorePaths("dateCreated", "dateModified");
		// 创建实例并查询
		Example<Student> ex = Example.of(queryObject, matcher);
		List<Student> result = dao.findAll(ex);
		return result;
	}

	@Autowired
	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
		this.dao = this.studentDao;
	}

}
